//
//  FQDetailListSectionController.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/17.
//

import UIKit

class FQDetailListSectionController: BaseListSectionController, ListSupplementaryViewSource {
    var model : FQDetailListModel!
    
    override init() {
        super.init()
        supplementaryViewSource = self
        inset = UIEdgeInsets(top: 0, left: 20, bottom: 10, right: 20)

    }
    
    func supportedElementKinds() -> [String] {
        [UICollectionView.elementKindSectionHeader]
    }

    func sizeForSupplementaryView(ofKind elementKind: String, at index: Int) -> CGSize {
        CGSize(width: SCREEN_WIDTH - 40, height: 64)
    }

    func viewForSupplementaryElement(ofKind elementKind: String, at index: Int) -> UICollectionReusableView {
        if elementKind != UICollectionView.elementKindSectionHeader || index != 0 {
            fatalError()
        }
        let view = collectionContext!.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, for: self, class: FQDetailListHeaderCollectionReusableView.self, at: index) as! FQDetailListHeaderCollectionReusableView
        return view
    }
    
    override func numberOfItems() -> Int {
        3
    }
    
    override func sizeForItem(at index: Int) -> CGSize {
        CGSize(width: SCREEN_WIDTH - 40, height: 63)
    }
    
    override func cellForItem(at index: Int) -> UICollectionViewCell {
        let cell = dequeueReusableCell(cellType: FQDetailListCollectionViewCell.self, index: index)
        cell.model = model
        cell.isLast = index == 3 - 1
        return cell
    }
    
    override func didSelectItem(at index: Int) {
      
    }
    
    override func didUpdate(to object: Any) {
        model = object as? FQDetailListModel
    }
}
